import axios from 'axios'
import { Indicator } from 'mint-ui';
let qs = require('qs')

let baseURL = ''

// baseURL = 'http://47.52.72.30:90/'
// baseURL = 'http://39.108.86.74:90/'
// baseURL = 'http://www.huashanglk.com:90/'
//baseURL = 'http://www.bitusec.com:90/'
// baseURL = 'http://192.168.2.129:90/'
// baseURL = 'http://www.th-coin.com:90/'
baseURL = 'http://118.31.62.10:90/'
// baseURL = 'http://block.jinanluke.com:90/'



const koaUrl = {
	local: 'http://127.0.0.1:8999/',
}

let tpost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
	},
	method: 'post',
})
let tpost2 = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'multipart/form-data',
	},
	method: 'post',
})
// 让java后台使用session
tpost.defaults.withCredentials = true
tpost2.defaults.withCredentials = true

// 临时调用的koa中间件
let koaPost = axios.create({
	baseURL: koaUrl.local,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
	},
	method: 'post',
})

let showResult = re => {
	// 测试环境用来看请求的结果
	return
	console.log(re)
}
// 设置过滤器
tpost.interceptors.response.use(

	function (response) {

		let re = response.data
		showResult(re)
		return re
	},
	function (error) {
		Indicator.close()
		return false
	},
)
koaPost.interceptors.response.use(
	function (response) {
		let re = response.data
		showResult(re)
		return re
	},
	function (error) {
		Indicator.close()
		return false
	},
)

let vpost = (link, setting) => {
	let s = qs.stringify(setting)
	showResult(s)
	return tpost.post(link, s)
}
let imgpost = (link, setting) => {
	return tpost2.post(link, setting)
}

let kpost = (link, setting) => {
	let s = qs.stringify(setting)
	return koaPost.post(link, s)
}

let getRan = () => {
	// 获取一个随机数, 一些接口要用到
	return (Math.random() * 100) | 0
}
let vlink = {
	changeLang: 'user/changeLang.html',
	sign: {
		in: 'user/login/index.html', // 登陆
		up: 'user/reg/index.html', // 注册
		forget: 'user/forgetPassword.html', //忘记密码
	},
	checkCode: {
		signup: {
			img: baseURL + 'servlet/ValidateImageServlet?r=', // 人机图片验证码
            phone: 'user/sendMsg.html?random=' + getRan(), // 发送手机验证码
            email:'user/sendMailCode.html?random=' + getRan(), // 发送短信验证码
		},
	},
	forgotPwd: {
		first: 'validate/resetPhoneValidation.html?random=' + getRan(), // 发送手机验证码
		next: 'validate/resetPasswordPhone.html?random=' + getRan(), // 提交确认
	},
	changepwd: 'user/modifyPwd.html?random=' + getRan(), // 修改登录密码
	news: 'app/point/getArticles.html', // 新闻中心
	newsBytype:'app/trade/informationList.html',//根据类型查询公告
	property: {
		own: 'financial/addConstant.html', // 获取用户钱包 以及各种币数量详情
	},
	auth: 'user/authentication.html?random=' + getRan(), // 实名认证
	authed: 'user/isReal.html', //实名认证成功 状态页面

	user: {
		signin: 'user/login/index.html', // 登陆
		signup: 'user/reg/index.html', // 注册
		tradePassword: 'user/modifyPwd.html', // (创建/修改)(交易/登陆)密码
		inviteHistory: 'introl/mydivideto.html?type=1', // 推广历史
		bindCard: 'user/center/bankCard.html', // 绑定银行卡
		bindWechat: 'user/addWX.html', // 绑定微信
		bindZhifubao: 'user/addZFB.html', // 绑定支付宝
		invite: 'introl/mydivideto.html?type=1', // 邀请信息获取
		getPai: 'introl/getPai.html?value=3',//获取排行信息
		walletInf: 'user/walletInf.html',//获取用户的财务账户信息
		deleteWall: 'user/deleteWall.html',
		ispassword: 'user/ispassword.html',//获取用户的密码
	},
	tradek: {
		buy: 'trade/buyBtcSubmit.html', // 买入
		sell: 'trade/sellBtcSubmit.html', // 卖出
		histroy: 'trade/entrustInfo.html', // 委托交易记录
		back: 'trade/cancelEntrust.html', // 撤销指定订单
		allBack: 'trade/cancelAllEntrust.html', // 撤销所有
		information: 'app/trade/coin.html', // 限价,交易记录
	},
	assets: {
		assetsList: 'financial/addConstant.html', //获取个人资产列表
	},
	addressManage: {
		//提币地址管理
		getCurrency: 'account/withdrawBtcCointype.html', //获取币种
		addAddress: 'user/modifyWithdrawBtcAddr.html', //添加提币地址
		getAddressInfo: 'account/fuserWithdrawBtcAddress.html', //获取提币地址
	},
	assetList: {
		getSingleAddress: 'account/rechargeBtc.html', //获取单个提币地址
		getAllAddress: 'account/withdrawBtcAddress.html', //获取币种对应的所有地址
		docoin: 'account/withdrawBtcSubmit.html', //申请提币
	},
	cwhistroy: {
		withdrawList: 'account/withdrawBtcList.html', //提现记录
		rechargeList: 'account/rechargeBtcList.html ', //充值记录
	},
	ddd: {//点对点接口补充
		getCointypes: 'introl/dddType.html',//查询允许交易的币种类型
		queryBalance: 'introl/quercount.html',//查询用户选择币种的余额
		getUserPayMethod: 'user/walletInf.html',//查询用户的支付方式
		releaseAdvert: 'introl/releaseOrder.html',//发布广告[fid,type,price,count,cointype,payMethods,password]
		queryAdvertByCointype: 'introl/selectCoinTypeOrder.html',//根据币种类型查询未成交的广告[type,cointype]
		queryAdvertByUser: 'introl/selectBuyOrder.html',//查询自己发布的广告[fid,type,cointype]
		cancelAdver: 'introl/cancelOrder.html',//取消广告[fid,orderId]
		deleteAdver: 'introl/deleteOrder.html',//删除已 取消/完成 的广告[fid,orderId]
		createOrder: 'introl/matchOrder.html',//创建订单[poid,fuid,count]
		lookOtherInf: 'introl/otherInformation.html',//查看交易对象信息[oid,uid]
		queryOrderBystatus: 'introl/selectSucFormOrder.html',//更具订单的状态查询订单[fid,status]1完成 0未完成
		completeOrder: 'introl/statusPayments.html',//完成订单[oid,uid,password]
		cancelOrder: 'introl/cancelOrderfrom.html',//取消订单[oid,uid]
		appealOrder: 'introl/statementOrder.html',//订单申诉[oid,uid,remarks]
		cancelAppeal: 'introl/calenStatementOrder.html',//取消申诉[oid,uid]
		uploadVoucher: 'introl/uploadVoucher.html',//上传凭证[filedata1,oid]
		getFee: 'introl/getFee.html',//查询手续费

	},
	bbTrade: {//币币交易接口补充
		getFrenchCurrency: 'app/trade/getFrenchCurrency.html',//查询允许交易的法币
		getTransactionPair: 'app/trade/getTransactionPair.html',//查询对应法币类型的交易对[cointypeId]
		getBBdata: 'app/trade/coin.html',//查询币币交易页面的详细数据[coinType]
		//dealList:'trade/dealList.html',//查询已成交的list[tradeMappingId]
		informationList: 'app/trade/informationList.html',//查询公告
		informationOne: 'app/trade/informationOne.html',//查询公告详情
		entrustInfo: 'app/trade/entrustInfo.html',//委托记录个人[symbol 币种,tradeType 类型0成交 1未成交]
		cancelUserEntrust: 'app/trade/cancelUserEntrust.html',//取消委托记录[id]
		getTransactionPairAll: 'app/trade/getTransactionPairAll.html',//查询所有的开放交易对信息
	},
	/**
	 * @Description: ${认购中心}
	 * @Param
	 * @Return
	 * @Author 焦政
	 * @Date 2018/12/3
	 * @Version 1.0
	 */
	subscriptionCenter:{
		getSubscriptionInfo:'tianhe/jiaoyizx.html',//获取认购信息
		doBuy:'tianhe/app/real/buyInRg.html',//认购
		jintai:'user/jingtai.html',//静态收益
		dongtai:'user/dongtai.html',//静态收益
	}
}
let klink = {
	getid: 'getid',
}

export { vpost, imgpost, kpost, vlink, klink }
